package com.hmall.common.utils;


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 雪花算法得到订单id
 */
@Component
@ConfigurationProperties(prefix = "order.snow")
public class SnowFlakeComponent {

    private static long workId;

    private static long datacenterId;

    private static volatile SnowFlake instance;

    /**
     * 获取实例
     *
     * @return
     */
    public static SnowFlake getInstance() {
        if (instance == null) {
            synchronized (SnowFlake.class) {
                if (instance == null) {
                    instance = new SnowFlake(workId, datacenterId);
                }
            }
        }
        return instance;
    }

}